(function () {
    ps = "absolute";
    class Food {
        constructor (option) { 
        var option = option instanceof Object ? option : {}
        this.width = option.width || 20
        this.height = option.height || 20
        this.x = option.x
        this.y = option.y
        this.color = option.color || "gold"
        this.eles = [
        }

        render (map) {
            var ele = document.createElement("div");
            ele.style.width = this.width + "px";
            ele.style.height = this.height + "px";
            this.x = Tools.getRandom(0,map.clientWidth / this.width - 1);
            this.y = Tools.getRandom(0,map.clientHeight / this.height - 1);
            ele.setAttribute("x",this.x)
            ele.setAttribute("y",this.y)
            ele.style.left = this.x * this.width + "px";
            ele.style.top =  this.y * this.height + "px";
            ele.style.backgroundColor = this.color;
            ele.style.position = ps;
            map.appendChild(ele);
            this.eles.push(ele)
        }

        remove (i) {
            this.eles[i].remove();
            this.eles.splice(i,1)
        }
    }
    window.Food = Food;
})()